-
-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only pass-through kwargs if super class can take them #81
base: main
Are you sure you want to change the base?
Conversation
@@ -72,7 +72,7 @@ def define_initialize_with_splat(super_parameters) | |||
else | |||
super_kwargs = slice_kwargs.(kwargs, super_parameters) | |||
|
|||
if super_kwargs.any? | |||
if super_kwargs.any? && super_parameters.keyword_names.any? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it allocate a new array every time when asking for keyword_names
? If yes, then it would be good to memoize it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I read it, keyword_names
are already memoized.
expect(instance.one).to eq 1 | ||
expect(instance.two).to eq 2 | ||
expect(instance.three).to eq 3 | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the expected behavior when you actually pass in kwargs to the constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean what is the expected behaviour if the super_klass
in this test accepts kwargs? I suspect that is probably still broken as it was before this change. It would be nice to get this working with kwargs too but I can't think of a good way to achieve that without checking every single argument the constructor accepts and attempting to match each one before calling super
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should raise an error when you include auto-injector module and the super constructor is not compatible. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree. Loud and noisy is good.
Fix for #80